package com.wawayaya.ui.bookcover;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.wawayaya.bean.Books;
import com.wawayaya.bookreader.ViewPages.NewBookPageView;
import com.wawayaya.util.ImageUtils;
import com.wawayaya.util.TLog;
import java.util.List;
import wawayaya.kids_iread.R;

/**
 * 图书封面
 */
public class BookCoverAdapter extends RecyclerView.Adapter<BookCoverHolder> {
    private final String  TAG = getClass().getSimpleName();
    private Context  context;
    private List<Books> books;
    private boolean   isZh;

    public BookCoverAdapter(Context context,boolean isZh,List<Books> books) {
        this.context = context;
        this.isZh = isZh;
        this.books = books;
    }

    @Override
    public int getItemCount() {
         int count = 0;
         if( books.size()>5){
             count = 5;
         }else{
             count = books.size();
         }
        return  count;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public BookCoverHolder onCreateViewHolder(ViewGroup vg, final int position) {
        View v = LayoutInflater.from(context).inflate(R.layout.book_cover, vg, false);
        return new BookCoverHolder(v);
    }

    private BookCoverHolder  holder;
    @Override
    public void onBindViewHolder(final BookCoverHolder holder, final int position) {
        final Books  book = books.get(position);
        this.holder = holder;
        holder.m_tvBookname.setText(isZh?book.getNameZh():book.getNameEn());

        String  str = "http://wawaqinpic.b0.upaiyun.com/";  //http://10.135.195.180:8086/
        ImageUtils.getImageLoader().displayImage(str+ book.getThumb(), holder.m_iv, ImageUtils.getCoverOptions());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TLog.log(TAG,"....on click...position:"+position);

            }
        });
    }

    public void updateProcess(int process,long bookId){
        holder.m_tvdownloadstatus.setText(process + "%");

        //notifyItemChanged();
    }

}
